<?php
class misc
{
    const NAME_SIZE=30;
    const LONG_NAME_SIZE=200;
    const BIT_OF_CHAR=8;
    const CRLF="\r\n";

    const DATE_SIZE=8;
    const TIME_SIZE=6;
    const TIMESTAMP_SIZE=14;

    public function str_is_dec($str)
    {/*{{{*/
        static $CHAR=array('0','1','2','3','4','5','6','7','8','9');
        $len=strlen($str);
        for($i=0; $i<$len; ++$i)
        {
            $c=substr($str, $i, 1);
            if(!in_array($c, $CHAR)) return false;
        }
        return true;
    }/*}}}*/

    public function str_is_hex($str)
    {/*{{{*/
        static $CHAR=array('0','1','2','3','4','5','6','7','8','9',
                'A','B','C','D','E','F','a','b','c','d','e','f');
        $len=strlen($str);
        for($i=0; $i<$len; ++$i)
        {
            $c=substr($str, $i, 1);
            if(!in_array($c, $CHAR)) return false;
        }
        return true;
    }/*}}}*/

    public function diff_millisecond($begin, $end)
    {/*{{{*/
        return ($end['sec']-$begin['sec'])*1000+
            ($end['usec']-$begin['usec'])/1000;
    }/*}}}*/
}
?>
